package com.scoy.honeymei.wxapi;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.scoy.honeymei.R;
import com.scoy.honeymei.base.BaseActivity;
import com.scoy.honeymei.url.MyUrl;
import com.scoy.honeymei.utils.MyUtil;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ClassName: WXPayEntryActivity$
 * @Description: 支付用wxpay
 * @Author: GaoZhan
 * @CreateDate: 2019/8/4/0004$ 下午 21:20$
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/8/4/0004$ 下午 21:20$
 * @UpdateRemark: 更新内容
 */
public class WXPayEntryActivity extends BaseActivity implements IWXAPIEventHandler {

    @Override
    public void initNormal() {

    }

    private IWXAPI api;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        api = WXAPIFactory.createWXAPI(this, MyUrl.APP_ID_WX);
        api.handleIntent(getIntent(), this);

        initNormal();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq req) {
    }

    @Override
    public void onResp(BaseResp resp) {
        Log.d("WXPAY", "--------onPayFinish 00, errCode = " + resp.errCode);
        if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
            int code = resp.errCode;
            switch (code) {
                case 0:
                    MyUtil.mytoast(this, "支付成功");
                    this.finish();
                    break;
                case -1:
                    MyUtil.mytoast(this, "支付失败");
                    this.finish();
                    break;
                case -2:
                    MyUtil.mytoast(this, "支付取消");
                    this.finish();
                    break;
                default:
                    MyUtil.mytoast(this, "支付失败");
                    setResult(RESULT_OK);
                    this.finish();
                    break;
            }

        }
    }

}
